package com.edu.exam.entity.classmanagement.administrative;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 班级分配类型枚举
 * 定义学生班级分配的方式
 *
 * @author System
 * @version 1.0.0
 */
public enum AssignmentType implements BaseEnum {

    AUTO("AUTO", "自动分配"),
    MANUAL("MANUAL", "手动分配"),
    BATCH("BATCH", "批量分配"),
    TRANSFER("TRANSFER", "转班分配");

    private final String code;
    private final String description;

    AssignmentType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static AssignmentType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("AssignmentType code cannot be null or empty");
        }
        for (AssignmentType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown assignment type code: " + code);
    }

    public static AssignmentType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("AssignmentType description cannot be null or empty");
        }
        for (AssignmentType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown assignment type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}